/// @tags: DPonTree
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 1e3 + 5, mod = 1e9 + 7;

struct Edge {
  int v, w, nxt;
} e[N << 2];

int heads[N], e_cnt;
int n, T, sz[N];
int f[N][N], g[N], pre[N][N], suf[N][N];
int C[N][N];

inline void addEdge(int u, int v, int w) {
  e[++e_cnt] = (Edge){v, w, heads[u]}, heads[u] = e_cnt;
}

inline void add(int& x, int y) { x = (x + y) % mod; }

inline void dfs(int u, int fa) {
  sz[u] = f[u][1] = 1;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v, w = e[i].w;
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
    memset(g, 0, sizeof(g));
    if (w) {
      for (int j = sz[u] - sz[v]; j; --j)
        for (int k = 0; k <= sz[v]; ++k)
          add(g[j + k], (LL)f[u][j] * C[j + k - 1][k] % mod *
                            C[sz[u] - j - k][sz[v] - k] % mod * pre[v][k] % mod);
    } else {
      for (int j = sz[u] - sz[v]; j; --j)
        for (int k = 0; k <= sz[v]; ++k)
          add(g[j + k], (LL)f[u][j] * C[j + k - 1][k] % mod *
                            C[sz[u] - j - k][sz[v] - k] % mod * suf[v][k + 1] % mod);
    }
    memcpy(f[u], g, sizeof(g));
  }
  pre[u][0] = suf[u][sz[u] + 1] = 0;
  for (int i = 1; i <= sz[u]; ++i) pre[u][i] = (pre[u][i - 1] + f[u][i]) % mod;
  for (int i = sz[u]; i >= 1; --i) suf[u][i] = (suf[u][i + 1] + f[u][i]) % mod;
}

inline void solve() {
  memset(heads, 0, sizeof(heads)), e_cnt = 0;
  memset(f, 0, sizeof(f));
  cin >> n;
  char typ;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> typ >> v;
    ++u, ++v;
    typ == '<' ? (addEdge(u, v, 0), addEdge(v, u, 1))
               : (addEdge(u, v, 1), addEdge(v, u, 0));
  }
  dfs(1, 1);
  int ans = 0;
  for (int i = 1; i <= n; ++i) add(ans, f[1][i]);
  cout << ans << '\n';
}

inline int main() {
  for (int i = 0; i < N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      if ((C[i][j] = C[i - 1][j] + C[i - 1][j - 1]) >= mod) C[i][j] -= mod;
  }
  cin >> T;
  while (T--) solve();
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4099 [HEOI2013] SAO.in", "r", stdin);
  freopen("P4099 [HEOI2013] SAO.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
